<template>
	<view class="income-page">
		<image class="bg" src="/static/income.png" mode="widthFix"></image>
		<u-navbar
			title="收益中心"
			autoBack
			placeholder
			leftIconColor="#fff"
			:titleStyle="{ color: '#fff' }"
			bgColor="transparent"
		></u-navbar>
		
		<view class="container">
			<view class="user-box">
				<image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
				<view class="name">{{ userInfo.name }}</view>
			</view>
			<view class="card-box">
				<view class="total">
					<view @click="goUrl('/pages/my/incomeRecord')">
						<view class="label">
							<text>累计{{ config.trade_currency }}收益</text>
							<u-icon name="arrow-right" color="#666" size="26rpx"></u-icon>
						</view>
						<view class="value">{{ userInfo.deposit_data.grand_total }}</view>
					</view>
					<view class="exchange" @click="goUrl('/pages/my/exchange')">
						<text class="text">{{ config.trade_currency }}互转</text>
					</view>
				</view>
				<view class="data">
					<view class="today">
						<view class="label">今日预估收益</view>
						<view class="value">{{ userInfo.deposit_data.grand_total_day }}</view>
					</view>
					<view class="withdraw">
						<view class="label">可提现</view>
						<view class="value">{{ userInfo.deposit }}</view>
					</view>
					<!-- <view class="dividend" @click="goUrl('/pages/my/dividend')">
						<view class="label">
							<text>我的分红</text>
							<u-icon name="arrow-right" color="#666" size="26rpx"></u-icon>
						</view>
						<view class="value">0</view>
					</view> -->
				</view>
				<button class="btn" @click="goWithdraw">立即提现</button>
				<view class="record" @click="goUrl('/pages/my/withdrawDetail')">
					<text>提现记录</text>
					<u-icon name="arrow-right" color="#5749f7" size="26rpx"></u-icon>
				</view>
			</view>
			<view class="info-box">
				<!-- <view class="item" @click="goUrl('/pages/my/contribution')">
					<view class="label">可兑换贡献值</view>
					<view class="value">
						<text>0</text>
						<u-icon name="arrow-right" color="#666" size="26rpx" bold></u-icon>
					</view>
				</view> -->
				<view class="item" @click="goUrl('/pages/my/gold')">
					<view class="label">{{ config.trade_currency_2 }}累计收益</view>
					<view class="value">
						<text>{{ userInfo.integral }}</text>
						<u-icon name="arrow-right" color="#666" size="26rpx" bold></u-icon>
					</view>
				</view>
			</view>
			<view class="tool-card">
				<view class="title-box">常用工具</view>
				<view class="list">
					<view class="item" @click="goUrl('/pages/my/team')">
						<image class="icon" src="@/static/tool-1.png" mode="aspectFill"></image>
						<view class="content">
							<view class="title">我的团队</view>
							<view class="label">{{ userInfo.tuan_num }}人</view>
						</view>
					</view>
					<!-- <view class="item" @click="goUrl('/pages/my/dividend')">
						<image class="icon" src="@/static/tool-2.png" mode="aspectFill"></image>
						<view class="content">
							<view class="title">分红入口</view>
							<view class="label">共同创造收益</view>
						</view>
					</view> -->
					<view class="item" @click="goUrl('/pages/my/gold')">
						<image class="icon" src="@/static/tool-3.png" mode="aspectFill"></image>
						<view class="content">
							<view class="title">我的{{ config.trade_currency_2 }}</view>
							<view class="label">{{ userInfo.integral }}{{ config.trade_currency_2 }}</view>
						</view>
					</view>
					<view class="item" @click="goUrl('/pages/my/foldback')">
						<image class="icon" src="@/static/tool-4.png" mode="aspectFill"></image>
						<view class="content">
							<view class="title">推三返一</view>
							<view class="label">推三返一</view>
						</view>
					</view>
					<view class="item" @click="goShare">
						<image class="icon" src="@/static/tool-5.png" mode="aspectFill"></image>
						<view class="content">
							<view class="title">推广海报</view>
							<view class="label">分享创收</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<u-popup :show="realShow" mode="center" round="16rpx" :safeAreaInsetBottom="false" closeable @close="show = false">
			<view class="real-popup">
				<image class="image" src="@/static/settlement-empty.png" mode="aspectFill"></image>
				<view class="text">您暂未实名，无法提现</view>
				<button class="btn" @click="goReal">去实名</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { getMaterial, getConfig } from '@/api/api'

	export default {
		data () {
			return {
				userInfo: {
					deposit_data: {}
				},
				
				config: {},
				realShow: false,
			}
		},
		onShow () {
			uni.showLoading({ mask: true })
			getMaterial().then(res => {
				uni.hideLoading({ noConflict: true })
				if (res) {
					this.userInfo = res.data.data
				}
			})
			
			getConfig().then(res => {
				if (res) {
					this.config = res.data
				}
			})
		},
		methods: {
			goUrl (url) {
				uni.navigateTo({
					url
				})
			},
			goShare () {
				uni.switchTab({
					url: '/pages/share/share'
				})
			},
			goWithdraw () {
				if (this.config.shiming_open == 0) {
					uni.navigateTo({
						url: '/pages/my/withdraw'
					})
				} else {
					if (this.userInfo.is_shi == 0) {
						this.realShow = true
					} else {
						uni.navigateTo({
							url: '/pages/my/withdraw'
						})
					}
				}
			},
			goReal () {
				this.realShow = false
				
				uni.navigateTo({
					url: '/pages/my/realName/realInfo'
				})
			}
		}
	}
</script>

<style lang="scss">
.income-page {
	min-height: 100%;
	background-color: $bg-color;
	position: relative;
	.bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
	}
	.container {
		position: relative;
		z-index: 10;
		padding: 90rpx 24rpx 24rpx;
		.user-box {
			padding: 0 14rpx;
			display: flex;
			align-items: center;
			.avatar {
				box-sizing: content-box;
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				border: 2rpx solid #fff;
			}
			.name {
				margin-left: 18rpx;
				color: #fff;
				font-size: 28rpx;
			}
		}
		.card-box {
			margin-top: 46rpx;
			padding: 50rpx;
			border-radius: 16rpx;
			background-color: #fff;
			.total {
				position: relative;
				.label {
					display: flex;
					align-items: center;
					color: #666;
					font-size: 26rpx;
				}
				.value {
					margin-top: 10rpx;
					color: #333;
					font-size: 42rpx;
					font-weight: bold;
				}
				.exchange {
					position: absolute;
					top: 26rpx;
					right: -50rpx;
					border-radius: 60rpx 0 0 60rpx;
					width: 182rpx;
					height: 60rpx;
					background-color: #edecff;
					color: #5749f7;
					display: flex;
					align-items: center;
					justify-content: center;
					.text {
						font-size: 26rpx;
						font-weight: bold;
					}
				}
			}
			.data {
				margin-top: 60rpx;
				display: flex;
				.today {
					// width: 252rpx;
					flex: 1;
					.value {
						color: #5749f7;
					}
				}
				.withdraw {
					flex: 1;
				}
				.dividend {
					padding-left: 44rpx;
					border-left: 1rpx solid #e5e5e5;
				}
				.label {
					display: flex;
					align-items: center;
					color: #666;
					font-size: 26rpx;
				}
				.value {
					margin-top: 4rpx;
					color: #333;
					font-size: 30rpx;
					font-weight: bold;
				}
			}
			.btn {
				margin-top: 66rpx;
				border-radius: 90rpx;
				height: 90rpx;
				color: #fff;
				font-size: 32rpx;
				font-weight: bold;
				line-height: 90rpx;
				background-color: #5749f7;
			}
			.record {
				margin-top: 36rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #5749f7;
				font-size: 26rpx;
			}
		}
		.info-box {
			margin-top: 12rpx;
			padding: 0 6rpx;
			.item {
				padding: 0 44rpx;
				border-radius: 8rpx;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				&:nth-child(1) {
					background: linear-gradient(90deg, #fff, #e9e6ff);
					.value {
						color: #5749f7;
					}
				}
				&:nth-child(2) {
					background: linear-gradient(90deg, #fff, #fff6eb);
					.value {
						color: #c48741;
					}
				}
				.label {
					color: #666;
					font-size: 28rpx;
					font-weight: bold;
				}
				.value {
					display: flex;
					align-items: center;
					font-size: 28rpx;
					font-weight: bold;
				}
			}
		}
		.tool-card {
			margin-top: 18rpx;
			padding: 32rpx;
			border-radius: 16rpx;
			background-color: #fff;
			.title-box {
				color: #000;
				font-size: 34rpx;
				font-weight: bold;
			}
			.list {
				margin-top: 50rpx;
				display: flex;
				flex-wrap: wrap;
				.item {
					width: 50%;
					display: flex;
					align-items: center;
					margin-bottom: 50rpx;
					&:nth-last-child(-n+2) {
						margin-bottom: 0;
					}
					.icon {
						width: 70rpx;
						height: 70rpx;
					}
					.content {
						flex: 1;
						margin-left: 18rpx;
						.title {
							color: #000;
							font-size: 26rpx;
							font-weight: bold;
						}
						.label {
							color: #999;
							font-size: 22rpx;
						}
					}
				}
			}
		}
	}
	.real-popup {
		box-sizing: border-box;
		padding: 90rpx 0 90rpx;
		width: 580rpx;
		text-align: center;
		.image {
			width: 204rpx;
			height: 204rpx;
		}
		.text {
			margin-top: 14rpx;
			color: #333;
			font-size: 34rpx;
			font-weight: bold;
		}
		.btn {
			margin: 88rpx auto 0;
			border-radius: 100rpx;
			width: 440rpx;
			height: 100rpx;
			color: #fff;
			font-size: 36rpx;
			font-weight: bold;
			line-height: 100rpx;
			background-color: #5749f7;
		}
	}
}
</style>
